home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / IEditor / Generators / C / data_misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  10.7 KB  |  389 lines

  1. /// Includes
  2. #define INTUI_V36_NAMES_ONLY
  3.  
  4. #include <exec/types.h>                 // exec
  5. #include <exec/lists.h>
  6. #include <exec/nodes.h>
  7. #include <dos/dos.h>                    // dos
  8. #include <dos/dostags.h>
  9. #include <intuition/intuition.h>        // intuition
  10. #include <graphics/text.h>              // graphics
  11. #include <libraries/gadtools.h>         // libraries
  12. #include <clib/exec_protos.h>           // protos
  13. #include <clib/dos_protos.h>
  14. #include <clib/intuition_protos.h>
  15. #include <pragmas/exec_pragmas.h>       // pragmas
  16. #include <pragmas/dos_pragmas.h>
  17. #include <pragmas/intuition_pragmas.h>
  18. #include <pragmas/gadtools_pragmas.h>
  19.  
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <ctype.h>
  24.  
  25. #include "DEV_IE:Generators/defs.h"
  26. #include "DEV_IE:Include/IEditor.h"
  27. #include "DEV_IE:Generators/C/Protos.h"
  28. ///
  29. /// Data
  30. static UBYTE   MenuTmp[] = "\nBOOL %sMenued( void )\n"
  31.             "{\n"
  32.             "\t/*  Routine for menu \"%s\"  */\n"
  33.             "\treturn( TRUE );\n"
  34.             "}\n";
  35. ///
  36.  
  37.  
  38. /// WriteMenuStruct
  39. void WriteMenuStruct( struct GenFiles *Files, struct IE_Data *IE )
  40. {
  41.     struct MenuTitle   *title;
  42.     struct _MenuItem   *item;
  43.     struct MenuSub     *sub;
  44.     struct WindowInfo  *wnd;
  45.     struct ImageNode   *img;
  46.     UBYTE               buffer[300], lent, leni, lens, *str, flags[100];
  47.     ULONG               smart;
  48.  
  49.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  50.     if( wnd->wi_NumMenus ) {
  51.  
  52.         smart = Prefs.Flags & SMART_STR;
  53.  
  54.         if( IE->SrcFlags & LOCALIZE )
  55.         smart = wnd->wi_Tags & W_LOC_MENUS;
  56.  
  57.         FPrintf( Files->Std, "\nstruct NewMenu %sNewMenu[] = {\n", wnd->wi_Label );
  58.  
  59.         for( title = wnd->wi_Menus.mlh_Head; title->mt_Node.ln_Succ; title = title->mt_Node.ln_Succ ) {
  60.  
  61.         FPuts( Files->Std, "\tNM_TITLE, (STRPTR)" );
  62.  
  63.         if( title->mt_Text[0] ) {
  64.             lent = strlen( title->mt_Text );
  65.             strcpy( buffer, title->mt_Text );
  66.             strcat( buffer, "/" );
  67.  
  68.             if( smart )
  69.             FPrintf( Files->Std, "%s", (( *IE->Functions->FindString )( &IE->Locale->ExtraStrings, title->mt_Text ))->ID );
  70.             else
  71.             FPrintf( Files->Std, "\"%s\"", title->mt_Text );
  72.         } else {
  73.             FPuts( Files->Std, Null );
  74.         }
  75.  
  76.         FPuts( Files->Std, ", NULL, " );
  77.  
  78.         if( title->mt_Flags & M_DISABLED )
  79.             FPuts( Files->Std, "NM_MENUDISABLED" );
  80.         else
  81.             FPuts( Files->Std, Null );
  82.  
  83.         FPuts( Files->Std, ", 0, NULL,\n" );
  84.  
  85.         for( item = title->mt_Items.mlh_Head; item->min_Node.ln_Succ; item = item->min_Node.ln_Succ ) {
  86.  
  87.             str = item->min_Image ? "\t  IM_ITEM" : "\t  NM_ITEM";
  88.             FPuts( Files->Std, str );
  89.  
  90.             leni = strlen( item->min_Text );
  91.             strcat( buffer, item->min_Text );
  92.  
  93.             FPuts( Files->Std, ", (STRPTR)" );
  94.  
  95.             if( item->min_Flags & M_BARLABEL ) {
  96.             FPuts( Files->Std, "NM_BARLABEL" );
  97.             } else {
  98.             if( img = item->min_Image ) {
  99.                 (ULONG)img -= sizeof( struct Node );
  100.                 FPrintf( Files->Std, "&%sImg", img->in_Label );
  101.             } else {
  102.                 if( item->min_Text[0] )
  103.                 if( smart )
  104.                     FPrintf( Files->Std, "%s", (( *IE->Functions->FindString )( &IE->Locale->ExtraStrings, item->min_Text ))->ID );
  105.                 else
  106.                     FPrintf( Files->Std, "\"%s\"", item->min_Text );
  107.                 else
  108.                 FPuts( Files->Std, Null );
  109.             }
  110.             }
  111.  
  112.             FPuts( Files->Std, ", " );
  113.  
  114.             if(!( item->min_NumSubs )) {
  115.             if( item->min_CommKey[0] ) {
  116.                 FPuts( Files->Std, "(STRPTR)" );
  117.                 if( smart )
  118.                 FPrintf( Files->Std, "%s", (( *IE->Functions->FindString )( &IE->Locale->ExtraStrings, item->min_CommKey ))->ID );
  119.                 else
  120.                 FPrintf( Files->Std, "\"%s\"", item->min_CommKey );
  121.             } else
  122.                 FPuts( Files->Std, Null );
  123.             } else {
  124.             FPuts( Files->Std, Null );
  125.             }
  126.  
  127.             flags[0] = '\0';
  128.  
  129.             if( item->min_Flags & M_DISABLED )
  130.             strcpy( flags, "NM_ITEMDISABLED|" );
  131.  
  132.             if( item->min_Flags & M_CHECKIT )
  133.             strcat( flags, "CHECKIT|" );
  134.  
  135.             if( item->min_Flags & M_CHECKED )
  136.             strcat( flags, "CHECKED|" );
  137.  
  138.             if( item->min_Flags & M_MENUTOGGLE )
  139.             strcat( flags, "MENUTOGGLE|" );
  140.  
  141.             if(!( item->min_NumSubs ))
  142.             if( item->min_CommKey[0] )
  143.                 if( item->min_CommKey[1] )
  144.                 strcat( flags, "NM_COMMANDSTRING|" );
  145.  
  146.             if(!( flags[0] ))
  147.             strcpy( flags, Null );
  148.             else
  149.             flags[ strlen( flags ) - 1 ] = '\0';
  150.  
  151.             FPrintf( Files->Std, ", %s, %ld, ", flags, item->min_MutualExclude );
  152.  
  153.             if(( Prefs.Flags & CLICKED ) && (!( item->min_NumSubs )) && (!( item->min_Flags & M_BARLABEL ))) {
  154.  
  155.             FPrintf( Files->XDef, "extern BOOL %sMenued( void );\n", item->min_Label );
  156.             FPrintf( Files->Std, "(APTR)%sMenued", item->min_Label );
  157.  
  158.             if( Prefs.Flags & GEN_TEMPLATE )
  159.                 FPrintf( Files->Temp, MenuTmp, item->min_Label, buffer );
  160.  
  161.             } else {
  162.             FPuts( Files->Std, Null );
  163.             }
  164.  
  165.             FPuts( Files->Std, ",\n" );
  166.  
  167.             strcat( buffer, "/" );
  168.  
  169.             for( sub = item->min_Subs.mlh_Head; sub->msn_Node.ln_Succ; sub = sub->msn_Node.ln_Succ ) {
  170.  
  171.             lens = strlen( sub->msn_Text );
  172.             strcat( buffer, sub->msn_Text );
  173.  
  174.             str = sub->msn_Image ? "\t    IM_SUB" : "\t    NM_SUB";
  175.             FPuts( Files->Std, str );
  176.  
  177.             FPuts( Files->Std, ", (STRPTR)" );
  178.  
  179.             if( sub->msn_Flags & M_BARLABEL ) {
  180.                 FPuts( Files->Std, "NM_BARLABEL" );
  181.             } else {
  182.                 if( img = sub->msn_Image ) {
  183.                 (ULONG)img -= sizeof( struct Node );
  184.                 FPrintf( Files->Std, "&%sImg", img->in_Label );
  185.                 } else {
  186.                 if( sub->msn_Text[0] )
  187.                     if( smart )
  188.                     FPrintf( Files->Std, "%s", (( *IE->Functions->FindString )( &IE->Locale->ExtraStrings, sub->msn_Text ))->ID );
  189.                     else
  190.                     FPrintf( Files->Std, "\"%s\"", sub->msn_Text );
  191.                 else
  192.                     FPuts( Files->Std, Null );
  193.                 }
  194.             }
  195.  
  196.             FPuts( Files->Std, ", " );
  197.  
  198.             if( sub->msn_CommKey[0] ) {
  199.                 FPuts( Files->Std, "(STRPTR)" );
  200.                 if( smart )
  201.                 FPrintf( Files->Std, "%s", (( *IE->Functions->FindString )( &IE->Locale->ExtraStrings, sub->msn_CommKey ))->ID );
  202.                 else
  203.                 FPrintf( Files->Std, "\"%s\"", sub->msn_CommKey );
  204.             } else
  205.                 FPuts( Files->Std, Null );
  206.  
  207.             flags[0] = '\0';
  208.  
  209.             if( sub->msn_Flags & M_DISABLED )
  210.                 strcpy( flags, "NM_ITEMDISABLED|" );
  211.  
  212.             if( sub->msn_Flags & M_CHECKIT )
  213.                 strcat( flags, "CHECKIT|" );
  214.  
  215.             if( sub->msn_Flags & M_CHECKED )
  216.                 strcat( flags, "CHECKED|" );
  217.  
  218.             if( sub->msn_Flags & M_MENUTOGGLE )
  219.                 strcat( flags, "MENUTOGGLE|" );
  220.  
  221.             if( sub->msn_CommKey[0] )
  222.                 if( sub->msn_CommKey[1] )
  223.                 strcat( flags, "NM_COMMANDSTRING|" );
  224.  
  225.             if(!( flags[0] ))
  226.                 strcpy( flags, Null );
  227.             else
  228.                 flags[ strlen( flags ) - 1 ] = '\0';
  229.  
  230.             FPrintf( Files->Std, ", %s, %ld, ", flags, sub->msn_MutualExclude );
  231.  
  232.             if(( Prefs.Flags & CLICKED ) && (!( sub->msn_Flags & M_BARLABEL ))) {
  233.  
  234.                 FPrintf( Files->XDef, "extern BOOL %sMenued( void );\n", sub->msn_Label );
  235.                 FPrintf( Files->Std, "(APTR)%sMenued", sub->msn_Label );
  236.  
  237.                 if( Prefs.Flags & GEN_TEMPLATE )
  238.                 FPrintf( Files->Temp, MenuTmp, sub->msn_Label, buffer );
  239.  
  240.             } else {
  241.                 FPuts( Files->Std, Null );
  242.             }
  243.  
  244.             FPuts( Files->Std, ",\n" );
  245.  
  246.             buffer[ lent+leni+2 ] = '\0';
  247.             }
  248.  
  249.             buffer[ lent+1 ] = '\0';
  250.         }
  251.         }
  252.  
  253.         FPuts( Files->Std, "\tNM_END, NULL, NULL, 0, 0L, NULL };\n" );
  254.     }
  255.     }
  256. }
  257. ///
  258. /// WriteITexts
  259. void WriteITexts( struct GenFiles *Files, struct IE_Data *IE )
  260. {
  261.     struct WindowInfo  *wnd;
  262.     struct ITextNode   *txt;
  263.     struct TxtAttrNode *fnt;
  264.     UWORD               x, y, next;
  265.     ULONG               loc;
  266.  
  267.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  268.     if( wnd->wi_NumTexts ) {
  269.  
  270.         loc = Prefs.Flags & SMART_STR;
  271.  
  272.         if( IE->SrcFlags & LOCALIZE )
  273.         loc = wnd->wi_Tags & W_LOC_TEXTS;
  274.  
  275.         FPrintf( Files->XDef, "extern struct IntuiText\t\t%sIText[];\n", wnd->wi_Label );
  276.         FPrintf( Files->Std, "\nstruct IntuiText %sIText[] = {\n", wnd->wi_Label );
  277.  
  278.         next = 1;
  279.  
  280.         for( txt = wnd->wi_ITexts.mlh_Head; txt->itn_Node.ln_Succ; txt = txt->itn_Node.ln_Succ ) {
  281.  
  282.         FPrintf( Files->Std, "\t%ld, %ld, %ld, ",
  283.              txt->itn_FrontPen, txt->itn_BackPen, txt->itn_DrawMode );
  284.  
  285.         x = txt->itn_LeftEdge - IE->ScreenData->XOffset;
  286.         y = txt->itn_TopEdge - IE->ScreenData->YOffset;
  287.  
  288.         if( IE->SrcFlags & FONTSENSITIVE ) {
  289.             x += ( IntuiTextLength(( struct IntuiText * )&txt->itn_FrontPen ) >> 1 );
  290.             y += ( IE->ScreenData->Screen->RastPort.TxHeight >> 1 );
  291.         }
  292.  
  293.         FPrintf( Files->Std, "%ld, %ld, ", x, y );
  294.  
  295.         if( fnt = txt->itn_ITextFont ) {
  296.             (ULONG)fnt -= sizeof( struct Node );
  297.             FPrintf( Files->Std, "&%s", fnt->txa_Label );
  298.         } else {
  299.             FPuts( Files->Std, Null );
  300.         }
  301.  
  302.         FPuts( Files->Std, ", (UBYTE *)" );
  303.  
  304.         if( loc )
  305.             FPrintf( Files->Std, "%s", (( *IE->Functions->FindString )( &IE->Locale->ExtraStrings, txt->itn_Text ))->ID );
  306.         else
  307.             FPrintf( Files->Std, "\"%s\"", txt->itn_Text );
  308.  
  309.         if((!( IE->SrcFlags & FONTSENSITIVE )) && ( next != wnd->wi_NumTexts )) {
  310.             FPrintf( Files->Std, ", &%sIText[%ld],\n", wnd->wi_Label, next );
  311.             next += 1;
  312.         } else {
  313.             FPuts( Files->Std, ", NULL,\n" );
  314.         }
  315.         }
  316.  
  317.         Flush( Files->Std );
  318.         Seek( Files->Std, -2, OFFSET_CURRENT );
  319.         FPuts( Files->Std, "\n};\n" );
  320.  
  321.     }
  322.     }
  323. }
  324. ///
  325. /// WriteImgStruct
  326. void WriteImgStruct( struct GenFiles *Files, struct IE_Data *IE )
  327. {
  328.     struct ImageNode   *img;
  329.  
  330.     for( img = IE->Img_List.mlh_Head; img->in_Node.ln_Succ; img = img->in_Node.ln_Succ ) {
  331.  
  332.     FPrintf( Files->XDef, "extern struct Image\t\t%sImg;\n", img->in_Label );
  333.     FPrintf( Files->Std, "\nstruct Image %sImg = {\n", img->in_Label );
  334.  
  335.     VFPrintf( Files->Std, "\t%d, %d,\n\t%d, %d, %d,\n\t", &img->in_Left );
  336.  
  337.     if( img->in_Size )
  338.         FPrintf( Files->Std, "%sImgData", img->in_Label );
  339.     else
  340.         FPuts( Files->Std, Null );
  341.  
  342.     FPrintf( Files->Std, ",\n\t%ld, %ld,\n\t0\n};\n",
  343.          img->in_PlanePick, img->in_PlaneOnOff );
  344.     }
  345. }
  346. ///
  347. /// WriteImageStruct
  348. void WriteImageStruct( struct GenFiles *Files, struct IE_Data *IE )
  349. {
  350.     struct WindowInfo  *wnd;
  351.     struct WndImages   *img;
  352.     UWORD               cnt;
  353.  
  354.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  355.  
  356.     cnt = 0;
  357.  
  358.     for( img = wnd->wi_Images.mlh_Head; img->wim_Next; img = img->wim_Next ) {
  359.  
  360.         FPrintf( Files->XDef, "extern struct Image\t\t%s_%ldImage;\n", wnd->wi_Label, cnt );
  361.         FPrintf( Files->Std, "\nstruct Image %s_%ldImage = {\n", wnd->wi_Label, cnt );
  362.  
  363.         cnt += 1;
  364.  
  365.         FPrintf( Files->Std, "\t%ld, %ld,\n\t%ld, %ld, %ld,\n\t",
  366.              img->wim_Left - IE->ScreenData->XOffset,
  367.              img->wim_Top  - IE->ScreenData->YOffset,
  368.              img->wim_Width, img->wim_Height, img->wim_Depth );
  369.  
  370.         if( img->wim_ImageNode->in_Size )
  371.         FPrintf( Files->Std, "%sImgData", img->wim_ImageNode->in_Label );
  372.         else
  373.         FPuts( Files->Std, Null );
  374.  
  375.         FPrintf( Files->Std, ",\n\t%ld, %ld,\n\t",
  376.              img->wim_PlanePick, img->wim_PlaneOnOff );
  377.  
  378.         if( cnt < wnd->wi_NumImages )
  379.         FPrintf( Files->Std, "&%s_%ldImage", wnd->wi_Label, cnt );
  380.         else
  381.         FPuts( Files->Std, Null );
  382.  
  383.         FPuts( Files->Std, "\n};\n" );
  384.     }
  385.     }
  386. }
  387. ///
  388.  
  389.